package printerDetection;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LinuxPrinterDetector implements PrinterDetector {

	@Override
	public String[] detectPrinters() {
		
		String [] printers;
		
		List<String> printersList = new ArrayList<String>();
		
		String printer = null;
		int i = 0;
		
		// list all printers
		try {
			Process detectPrinters = Runtime.getRuntime().exec("lpstat -a"); 
			
			Scanner sc = new Scanner(detectPrinters.getInputStream());

			while (sc.hasNext()){
				printersList.add(sc.next());
				System.out.println(printer);
				sc.nextLine();
			}
		} catch (Exception e){
			System.out.println("detecting printers is evil!");
		}
		
		printers = new String[printersList.size()];
		
		for (String p: printersList)
			printers[i++] = p;
	
		return printers;
	}
}
